"""
Case Type   : Compatibility
Case Name   : 验证字符串处理函数的bool值输出
Create At   : 2024/10/21
Owner       : liu-tong-8848
Description :
              1.notlike函数
              2.regexp_like函数
              3.string [NOT] LIKE pattern函数
Expect      :
              1.成功
              2.成功
              3.成功
History     :
"""

import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node


class SQL(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.Constant = Constant()
        self.primary_sh = CommonSH('PrimaryDbBmode')
        self.db_user_node = Node(node='PrimaryDbBmode')

    def test_add_dimension(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        step1 = '--step1：notlike函数 expect：执行成功'
        self.log.info(step1)
        sql = "select notlike('abc','def') as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step1)
        sql = "select notlike(1,1) as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step1)
        sql = "select notlike('true','false')as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step1)
        sql = "select notlike(0,'false')as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step1)

        step2 = '--step2：regexp_like函数 expect：执行成功'
        self.log.info(step2)
        sql = "select regexp_like('str','st*')as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step2)
        sql = " select regexp_like('str','a%')as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step2)
        sql = "select regexp_like('1234','[5%]')as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step2)
        sql = "select regexp_like('1234','[_2%]')as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step2)

        step3 = '--step3：string [NOT] LIKE pattern函数 expect：执行成功'
        self.log.info(step3)
        sql = "select 'aa_bbcc' like '%a@_b%' escape '@' as c; "
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step3)
        sql = "select 'aa_bbcc' not like '%a@_b%' escape '@' as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step3)
        sql = "select 'aa_bbcc' like '%a@_b%' as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step3)
        sql = "select 'aa@_bbcc' like '%a@_b%' as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step3)

    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
